"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
    return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var vue_1 = require("vue");
var pictureController_ts_1 = require("@/api/pictureController.ts");
var ant_design_vue_1 = require("ant-design-vue");
var useLoginUserStore_ts_1 = require("@/stores/useLoginUserStore.ts");
var props = defineProps();
// 编辑器组件的引用
var cropperRef = (0, vue_1.ref)();
// 向左旋转
var rotateLeft = function () {
    cropperRef.value.rotateLeft();
};
// 向右旋转
var rotateRight = function () {
    cropperRef.value.rotateRight();
};
// 缩放
var changeScale = function (num) {
    cropperRef.value.changeScale(num);
};
// 是否可见
var visible = (0, vue_1.ref)(false);
// 打开弹窗
var openModal = function () {
    visible.value = true;
};
// 暴露函数给父组件
var __VLS_exposed = {
    openModal: openModal,
};
defineExpose({
    openModal: openModal,
});
var loading = (0, vue_1.ref)(false);
// 确认裁剪
var handleConfirm = function () {
    cropperRef.value.getCropBlob(function (blob) {
        var _a;
        var fileName = (((_a = props.picture) === null || _a === void 0 ? void 0 : _a.name) || 'image') + '.png';
        var file = new File([blob], fileName, { type: blob.type });
        // 上传图片
        handleUpload({ file: file });
    });
};
/**
 * 上传
 * @param file
 */
var handleUpload = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
    var params, res, error_1;
    var _c;
    var file = _b.file;
    return __generator(this, function (_d) {
        switch (_d.label) {
            case 0:
                loading.value = true;
                _d.label = 1;
            case 1:
                _d.trys.push([1, 3, 4, 5]);
                params = props.picture ? { id: props.picture.id } : {};
                params.spaceId = props.spaceId;
                return [4 /*yield*/, (0, pictureController_ts_1.uploadPictureUsingPost)(params, {}, file)];
            case 2:
                res = _d.sent();
                if (res.data.code === 0 && res.data.data) {
                    ant_design_vue_1.message.success('图片上传成功');
                    // 将上传成功的图片信息传递给父组件
                    (_c = props.onSuccess) === null || _c === void 0 ? void 0 : _c.call(props, res.data.data);
                    closeModal();
                }
                else {
                    ant_design_vue_1.message.error('图片上传失败，' + res.data.message);
                }
                return [3 /*break*/, 5];
            case 3:
                error_1 = _d.sent();
                ant_design_vue_1.message.error('图片上传失败');
                return [3 /*break*/, 5];
            case 4:
                loading.value = false;
                return [7 /*endfinally*/];
            case 5: return [2 /*return*/];
        }
    });
}); };
// --------- 实时编辑 ---------
var loginUserStore = (0, useLoginUserStore_ts_1.useLoginUserStore)();
var loginUser = loginUserStore.loginUser;
// 正在编辑的用户
var editingUser = (0, vue_1.ref)();
// 没有用户正在编辑中，可进入编辑
var canEnterEdit = (0, vue_1.computed)(function () {
    return !editingUser.value;
});
// 正在编辑的用户是本人，可退出编辑
var canExitEdit = (0, vue_1.computed)(function () {
    var _a;
    return ((_a = editingUser.value) === null || _a === void 0 ? void 0 : _a.id) === loginUser.id;
});
// 可以编辑
var canEdit = (0, vue_1.computed)(function () {
    var _a;
    return ((_a = editingUser.value) === null || _a === void 0 ? void 0 : _a.id) === loginUser.id;
});
var websocket;
// 初始化 WebSocket 连接，绑定事件
var initWebsocket = function () {
    var _a;
    var pictureId = (_a = props.picture) === null || _a === void 0 ? void 0 : _a.id;
    if (!pictureId || !visible.value) {
        return;
    }
    // 防止之前的连接未释放
    if (websocket) {
        websocket.disconnect();
    }
    // 创建 WebSocket 实例
    websocket = new PictureEditWebSocket(pictureId);
    // 建立 WebSocket 连接
    websocket.connect();
    // 监听通知消息
    websocket.on(PICTURE_EDIT_MESSAGE_TYPE_ENUM.INFO, function (msg) {
        console.log('收到通知消息：', msg);
        ant_design_vue_1.message.info(msg.message);
    });
    // 监听错误消息
    websocket.on(PICTURE_EDIT_MESSAGE_TYPE_ENUM.ERROR, function (msg) {
        console.log('收到错误消息：', msg);
        ant_design_vue_1.message.error(msg.message);
    });
    // 监听进入编辑状态消息
    websocket.on(PICTURE_EDIT_MESSAGE_TYPE_ENUM.ENTER_EDIT, function (msg) {
        console.log('收到进入编辑状态消息：', msg);
        ant_design_vue_1.message.info(msg.message);
        editingUser.value = msg.user;
    });
    // 监听编辑操作消息
    websocket.on(PICTURE_EDIT_MESSAGE_TYPE_ENUM.EDIT_ACTION, function (msg) {
        console.log('收到编辑操作消息：', msg);
        ant_design_vue_1.message.info(msg.message);
        switch (msg.editAction) {
            case PICTURE_EDIT_ACTION_ENUM.ROTATE_LEFT:
                cropperRef.value.rotateLeft();
                break;
            case PICTURE_EDIT_ACTION_ENUM.ROTATE_RIGHT:
                cropperRef.value.rotateRight();
                break;
            case PICTURE_EDIT_ACTION_ENUM.ZOOM_IN:
                cropperRef.value.changeScale(1);
                break;
            case PICTURE_EDIT_ACTION_ENUM.ZOOM_OUT:
                cropperRef.value.changeScale(-1);
                break;
        }
    });
    // 监听退出编辑状态消息
    websocket.on(PICTURE_EDIT_MESSAGE_TYPE_ENUM.EXIT_EDIT, function (msg) {
        console.log('收到退出编辑状态消息：', msg);
        ant_design_vue_1.message.info(msg.message);
        editingUser.value = undefined;
    });
};
(0, vue_1.watchEffect)(function () {
    initWebsocket();
});
(0, vue_1.onUnmounted)(function () {
    // 断开连接
    if (websocket) {
        websocket.disconnect();
    }
    editingUser.value = undefined;
});
// 关闭弹窗
var closeModal = function () {
    visible.value = false;
    // 断开连接
    if (websocket) {
        websocket.disconnect();
    }
    editingUser.value = undefined;
}; /* PartiallyEnd: #3632/scriptSetup.vue */
function __VLS_template() {
    var __VLS_ctx = {};
    var __VLS_components;
    var __VLS_directives;
    ['image-cropper',];
    // CSS variable injection 
    // CSS variable injection end 
    var __VLS_0 = {}.AModal;
    /** @type { [typeof __VLS_components.AModal, typeof __VLS_components.aModal, typeof __VLS_components.AModal, typeof __VLS_components.aModal, ] } */ ;
    // @ts-ignore
    var __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0(__assign(__assign({ 'onCancel': {} }, { class: ("image-cropper") }), { visible: ((__VLS_ctx.visible)), title: ("编辑图片"), footer: ((false)) })));
    var __VLS_2 = __VLS_1.apply(void 0, __spreadArray([__assign(__assign({ 'onCancel': {} }, { class: ("image-cropper") }), { visible: ((__VLS_ctx.visible)), title: ("编辑图片"), footer: ((false)) })], __VLS_functionalComponentArgsRest(__VLS_1), false));
    var __VLS_6 = {};
    var __VLS_7;
    var __VLS_8 = {
        onCancel: (__VLS_ctx.closeModal)
    };
    var __VLS_3;
    var __VLS_4;
    var __VLS_9 = {}.VueCropper;
    /** @type { [typeof __VLS_components.VueCropper, typeof __VLS_components.vueCropper, ] } */ ;
    // @ts-ignore
    var __VLS_10 = __VLS_asFunctionalComponent(__VLS_9, new __VLS_9({
        ref: ("cropperRef"),
        img: ((__VLS_ctx.imageUrl)),
        autoCrop: ((true)),
        fixedBox: ((false)),
        centerBox: ((true)),
        canMoveBox: ((true)),
        info: ((true)),
        outputType: ("png"),
    }));
    var __VLS_11 = __VLS_10.apply(void 0, __spreadArray([{
            ref: ("cropperRef"),
            img: ((__VLS_ctx.imageUrl)),
            autoCrop: ((true)),
            fixedBox: ((false)),
            centerBox: ((true)),
            canMoveBox: ((true)),
            info: ((true)),
            outputType: ("png"),
        }], __VLS_functionalComponentArgsRest(__VLS_10), false));
    // @ts-ignore navigation for `const cropperRef = ref()`
    /** @type { typeof __VLS_ctx.cropperRef } */ ;
    var __VLS_15 = {};
    var __VLS_14;
    __VLS_elementAsFunction(__VLS_intrinsicElements.div)(__assign({ style: ({}) }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("image-edit-actions") }));
    var __VLS_16 = {}.ASpace;
    /** @type { [typeof __VLS_components.ASpace, typeof __VLS_components.aSpace, typeof __VLS_components.ASpace, typeof __VLS_components.aSpace, ] } */ ;
    // @ts-ignore
    var __VLS_17 = __VLS_asFunctionalComponent(__VLS_16, new __VLS_16({}));
    var __VLS_18 = __VLS_17.apply(void 0, __spreadArray([{}], __VLS_functionalComponentArgsRest(__VLS_17), false));
    if (__VLS_ctx.editingUser) {
        var __VLS_22 = {}.AButton;
        /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
        // @ts-ignore
        var __VLS_23 = __VLS_asFunctionalComponent(__VLS_22, new __VLS_22({
            disabled: (true),
        }));
        var __VLS_24 = __VLS_23.apply(void 0, __spreadArray([{
                disabled: (true),
            }], __VLS_functionalComponentArgsRest(__VLS_23), false));
        (__VLS_ctx.editingUser.userName);
        __VLS_27.slots.default;
        var __VLS_27;
    }
    if (__VLS_ctx.canEnterEdit) {
        var __VLS_28 = {}.AButton;
        /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
        // @ts-ignore
        var __VLS_29 = __VLS_asFunctionalComponent(__VLS_28, new __VLS_28(__assign({ 'onClick': {} }, { type: ("primary"), ghost: (true) })));
        var __VLS_30 = __VLS_29.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { type: ("primary"), ghost: (true) })], __VLS_functionalComponentArgsRest(__VLS_29), false));
        var __VLS_34 = void 0;
        var __VLS_35 = {
            onClick: (__VLS_ctx.enterEdit)
        };
        var __VLS_31 = void 0;
        var __VLS_32 = void 0;
        __VLS_33.slots.default;
        var __VLS_33;
    }
    if (__VLS_ctx.canExitEdit) {
        var __VLS_36 = {}.AButton;
        /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
        // @ts-ignore
        var __VLS_37 = __VLS_asFunctionalComponent(__VLS_36, new __VLS_36(__assign({ 'onClick': {} }, { danger: (true), ghost: (true) })));
        var __VLS_38 = __VLS_37.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { danger: (true), ghost: (true) })], __VLS_functionalComponentArgsRest(__VLS_37), false));
        var __VLS_42 = void 0;
        var __VLS_43 = {
            onClick: (__VLS_ctx.exitEdit)
        };
        var __VLS_39 = void 0;
        var __VLS_40 = void 0;
        __VLS_41.slots.default;
        var __VLS_41;
    }
    __VLS_21.slots.default;
    var __VLS_21;
    __VLS_elementAsFunction(__VLS_intrinsicElements.div)(__assign({ style: ({}) }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("image-cropper-actions") }));
    var __VLS_44 = {}.ASpace;
    /** @type { [typeof __VLS_components.ASpace, typeof __VLS_components.aSpace, typeof __VLS_components.ASpace, typeof __VLS_components.aSpace, ] } */ ;
    // @ts-ignore
    var __VLS_45 = __VLS_asFunctionalComponent(__VLS_44, new __VLS_44({}));
    var __VLS_46 = __VLS_45.apply(void 0, __spreadArray([{}], __VLS_functionalComponentArgsRest(__VLS_45), false));
    var __VLS_50 = {}.AButton;
    /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
    // @ts-ignore
    var __VLS_51 = __VLS_asFunctionalComponent(__VLS_50, new __VLS_50(__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })));
    var __VLS_52 = __VLS_51.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })], __VLS_functionalComponentArgsRest(__VLS_51), false));
    var __VLS_56;
    var __VLS_57 = {
        onClick: (__VLS_ctx.rotateLeft)
    };
    var __VLS_53;
    var __VLS_54;
    __VLS_55.slots.default;
    var __VLS_55;
    var __VLS_58 = {}.AButton;
    /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
    // @ts-ignore
    var __VLS_59 = __VLS_asFunctionalComponent(__VLS_58, new __VLS_58(__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })));
    var __VLS_60 = __VLS_59.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })], __VLS_functionalComponentArgsRest(__VLS_59), false));
    var __VLS_64;
    var __VLS_65 = {
        onClick: (__VLS_ctx.rotateRight)
    };
    var __VLS_61;
    var __VLS_62;
    __VLS_63.slots.default;
    var __VLS_63;
    var __VLS_66 = {}.AButton;
    /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
    // @ts-ignore
    var __VLS_67 = __VLS_asFunctionalComponent(__VLS_66, new __VLS_66(__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })));
    var __VLS_68 = __VLS_67.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })], __VLS_functionalComponentArgsRest(__VLS_67), false));
    var __VLS_72;
    var __VLS_73 = {
        onClick: function () {
            var _a = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                _a[_i] = arguments[_i];
            }
            var $event = _a[0];
            __VLS_ctx.changeScale(1);
        }
    };
    var __VLS_69;
    var __VLS_70;
    __VLS_71.slots.default;
    var __VLS_71;
    var __VLS_74 = {}.AButton;
    /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
    // @ts-ignore
    var __VLS_75 = __VLS_asFunctionalComponent(__VLS_74, new __VLS_74(__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })));
    var __VLS_76 = __VLS_75.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { disabled: ((!__VLS_ctx.canEdit)) })], __VLS_functionalComponentArgsRest(__VLS_75), false));
    var __VLS_80;
    var __VLS_81 = {
        onClick: function () {
            var _a = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                _a[_i] = arguments[_i];
            }
            var $event = _a[0];
            __VLS_ctx.changeScale(-1);
        }
    };
    var __VLS_77;
    var __VLS_78;
    __VLS_79.slots.default;
    var __VLS_79;
    var __VLS_82 = {}.AButton;
    /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
    // @ts-ignore
    var __VLS_83 = __VLS_asFunctionalComponent(__VLS_82, new __VLS_82(__assign({ 'onClick': {} }, { type: ("primary"), loading: ((__VLS_ctx.loading)), disabled: ((!__VLS_ctx.canEdit)) })));
    var __VLS_84 = __VLS_83.apply(void 0, __spreadArray([__assign({ 'onClick': {} }, { type: ("primary"), loading: ((__VLS_ctx.loading)), disabled: ((!__VLS_ctx.canEdit)) })], __VLS_functionalComponentArgsRest(__VLS_83), false));
    var __VLS_88;
    var __VLS_89 = {
        onClick: (__VLS_ctx.handleConfirm)
    };
    var __VLS_85;
    var __VLS_86;
    __VLS_87.slots.default;
    var __VLS_87;
    __VLS_49.slots.default;
    var __VLS_49;
    __VLS_5.slots.default;
    var __VLS_5;
    ['image-cropper', 'image-edit-actions', 'image-cropper-actions',];
    var __VLS_slots;
    var $slots;
    var __VLS_inheritedAttrs;
    var $attrs;
    var __VLS_refs = {
        'cropperRef': __VLS_15,
    };
    var $refs;
    var $el;
    return {
        attrs: {},
        slots: __VLS_slots,
        refs: $refs,
        rootEl: $el,
    };
}
;
var __VLS_self = (await Promise.resolve().then(function () { return __importStar(require('vue')); })).defineComponent({
    setup: function () {
        return {
            cropperRef: cropperRef,
            rotateLeft: rotateLeft,
            rotateRight: rotateRight,
            changeScale: changeScale,
            visible: visible,
            loading: loading,
            handleConfirm: handleConfirm,
            editingUser: editingUser,
            canEnterEdit: canEnterEdit,
            canExitEdit: canExitEdit,
            canEdit: canEdit,
            closeModal: closeModal,
        };
    },
    __typeProps: {},
});
exports.default = (await Promise.resolve().then(function () { return __importStar(require('vue')); })).defineComponent({
    setup: function () {
        return __assign({}, __VLS_exposed);
    },
    __typeProps: {},
    __typeRefs: {},
    __typeEl: {},
});
; /* PartiallyEnd: #4569/main.vue */
